<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}

$table_configs = C::t('#erling_account_center#er_account_config');

if(submitcheck('configsubmit')) {
    $configs = $_POST['config'];
    foreach($configs as $key => $value) {
        $result = $table_configs->update_by_key($key, array('value' => $value));
        if(!$result['success']) {
            $errors[] = "配置项 {$key} 更新失败：{$result['message']}";
        }
    }
    
    if(empty($errors)) {
        cpmsg('setting_update_success', 'action=plugins&operation=config&do='.$pluginid.'&identifier=erling_account_center&pmod=admin_config', 'succeed');
    } else {
        cpmsg(implode('<br>', $errors), 'action=plugins&operation=config&do='.$pluginid.'&identifier=erling_account_center&pmod=admin_config', 'error');
    }
}

$settings = $table_configs->fetch_by_keys(array('redirect_url', 'appid', 'app_secret', 'only_acount_auth'));

showformheader('plugins&operation=config&do='.$pluginid.'&identifier=erling_account_center&pmod=admin_config');
showtableheader('账号中心配置');

showsetting('重定向URL', 'config[redirect_url]', $settings['redirect_url']['value'], 'text', '', 0, '', 200);
showsetting('应用ID', 'config[appid]', $settings['appid']['value'], 'text', '', 0, '', 50);
showsetting('应用密钥', 'config[app_secret]', $settings['app_secret']['value'], 'text', '', 0, '', 50);
showsetting('只允许聚合账号登录', 'config[only_acount_auth]', $settings['only_acount_auth']['value'], 'radio', array('0' => '不限制', '1' => '限制'), 0, '', 50);

showsubmit('configsubmit', 'submit', '保存', '', '&nbsp;&nbsp;<a href="javascript:;" onclick="history.back()" class="lightlink">返回</a>');
showtablefooter();
showformfooter();